﻿using NPOI.SS.UserModel;

namespace File.Api.Utils
{
    public static class ExcelStyleUtils
    {
        public static ICellStyle GetExcelHeaderOQCStyle(IWorkbook workbook)
        {
            ICellStyle boldStyle = workbook.CreateCellStyle();

            var boldFont = workbook.CreateFont();
            boldFont.IsBold = true;
            boldFont.FontHeightInPoints = 11;
            boldStyle.BorderBottom = BorderStyle.Thin;
            boldStyle.BorderLeft = BorderStyle.Thin;
            boldStyle.BorderRight = BorderStyle.Thin;
            boldStyle.BorderTop = BorderStyle.Thin;
            boldStyle.Alignment = HorizontalAlignment.Center;
            boldStyle.VerticalAlignment = VerticalAlignment.Center;
            boldStyle.SetFont(boldFont);
            return boldStyle;
        }

        public static ICellStyle GetExcelHeaderStyle(IWorkbook workbook)
        {
            ICellStyle boldStyle = workbook.CreateCellStyle();

            var boldFont = workbook.CreateFont();
            boldFont.FontHeightInPoints = 11;
            boldStyle.SetFont(boldFont);
            boldStyle.BorderBottom = BorderStyle.Thin;
            boldStyle.BorderLeft = BorderStyle.Thin;
            boldStyle.BorderRight = BorderStyle.Thin;
            boldStyle.BorderTop = BorderStyle.Thin;
            return boldStyle;
        }

        public static ICellStyle GetExcelOQCStyle(IWorkbook workbook)
        {
            ICellStyle boldStyle = workbook.CreateCellStyle();

            var boldFont = workbook.CreateFont();
            boldFont.FontHeightInPoints = 11;
            boldStyle.SetFont(boldFont);
            boldStyle.BorderBottom = BorderStyle.Thin;
            boldStyle.BorderLeft = BorderStyle.Thin;
            boldStyle.BorderRight = BorderStyle.Thin;
            boldStyle.BorderTop = BorderStyle.Thin;
            boldStyle.Alignment = HorizontalAlignment.Center;
            boldStyle.VerticalAlignment = VerticalAlignment.Center;
            boldStyle.WrapText = true;
            return boldStyle;
        }

        public static void SetRowWrapText(IWorkbook workbook, IRow row)
        {
            ICellStyle notesStyle = workbook.CreateCellStyle();
            notesStyle.WrapText = true;
            notesStyle.VerticalAlignment = VerticalAlignment.Top;
            notesStyle.BorderBottom = BorderStyle.Thin;
            notesStyle.BorderLeft = BorderStyle.Thin;
            notesStyle.BorderRight = BorderStyle.Thin;
            notesStyle.BorderTop = BorderStyle.Thin;
            row.Cells.ForEach(item =>
            {
                item.CellStyle = notesStyle;
            });
        }
    }
}
